﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BasicForms
{
    public partial class FrmExceptionNotifier : BasicForms.FrmBase
    {
        private FrmExceptionNotifier(string exceptionDescription, string exceptionPosition)
        {
            InitializeComponent();
            this.AcceptButton = btnClose;
            txtExceptionDescription.Text = exceptionDescription;
            txtExceptionPosition.Text = exceptionPosition;
            AccountingLibs.CustomException.WriteLog(string.Format("Lỗi \"{0}\" tại {1}\n-----------------------------------------------------\n", 
                exceptionDescription, exceptionPosition));
        }

        public static void ShowAndLog(Exception ex)
        {
            //FrmExceptionNotifier frm = new FrmExceptionNotifier(ex.Message, ex.StackTrace.Substring(0, ex.StackTrace.IndexOf("\n")).Substring(3));
            FrmExceptionNotifier frm = new FrmExceptionNotifier(ex.Message, ex.StackTrace.Substring(3));
            frm.ShowDialog();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}
